<?php
class keu_kas_bank_coa_model extends MY_Model {
	var $model = 'keu_kas_bank_coa';
	
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	kb.id_coa, kb.keterangan, coa.nama_coa, bank.nama_bank, bank.kd_bank
					FROM	keu_kas_bank_coa kb INNER JOIN keu_coa coa ON coa.id_coa = kb.id_coa
							LEFT JOIN keu_bank bank ON bank.kd_bank = kb.kd_bank
					WHERE	
							(UPPER(coa.nama_coa) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(bank.nama_bank) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(kb.id_coa) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(kb.keterangan) LIKE UPPER('%".post('keyword')."%')							
							)
					ORDER BY ".(post('sort')=='' ? 'kb.id_coa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	
	function Add($arr_data){
		$this->db->insert('keu_kas_bank_coa', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('keu_kas_bank_coa', $arr_data, $arr_rule);
	}
	
	function GetSingle($id_coa){
		$result = $this->db->get_where('keu_kas_bank_coa', array('id_coa' => $id_coa));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($id_coa)
	{
		$ls_sql	= "	SELECT	kb.*, coa.nama_coa, bank.nama_bank
					FROM	keu_kas_bank_coa kb INNER JOIN keu_coa coa ON coa.id_coa = kb.id_coa
							LEFT JOIN keu_bank bank ON bank.kd_bank = kb.kd_bank
					WHERE	kb.id_coa = '".$id_coa."'
							";
							
		$result	= $this->db->query($ls_sql);
		
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	
	function DeleteSingle($as_code)
	{
		try {
			$this->db->delete('keu_kas_bank_coa', array('id_coa' => $as_code));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
	

}
?>